'''
@Company: TWL
@Author: xue jian
@Email: xuejian@kanzhun.com
@Date: 2020-02-01 20:52:08
'''
import os
import sys
import json
sys.path.append(os.path.abspath(os.path.join(os.path.dirname('__file__'), os.path.pardir)))

import thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from hulk_proxy.HulkProxyServ import Client
from scan_data.ttypes import ScanData

__HOST = "172.21.32.54"
__PORT = 10088

try:
    tsocket = TSocket.TSocket(__HOST, __PORT)
    transport = TTransport.TFramedTransport(tsocket)
    protocol = TBinaryProtocol.TBinaryProtocol(transport)
    client = Client(protocol)

    transport.open()
    '''
    @note: read model names
    '''
    models = client.get('boss_predict_online_model_names')
    # print(models)
    models = models.split(',')
    # print(models)
    for name in models:
        print(name)
        type_info = client.hget(name, 'type')
        print(type_info)
        if type_info != 'galaxy':
            continue
        info = client.hgetall(name)
        print('model name:', name, '\turl:', info['url'], '\tthe layer file store in /model/'+name+'.net')
        f = open('./models/' + name + '.net', 'w')
        f.write(info['layer'])
        f.close()
    


    transport.close()
except thrift.TException as ex:
    print(ex.message)